package servlet.PropertyManagementModule.CostManagement;

import bean.dto.CostPage;
import bean.pojo.User;
import bean.vo.CostOption;
import bean.vo.PeopleCostVo;
import bean.vo.UserVo;
import com.alibaba.fastjson.JSON;
import commons.r.R;
import commons.xlhUtils.MyFormatUtils;
import service.CostManagementService;
import service.ExpenseTypeService;
import service.PeopleCostMangerService;
import service.UsersService;
import service.impl.CostManagementServiceImpl;
import service.impl.ExpenseTypeServiceImpl;
import service.impl.PeopleCostMangerServiceImpl;
import service.impl.UsersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

/**
 * servlet.PropertyManagementModule.CostManagement
 * User: xlh
 * Date: 2024/12/19 14:43
 * motto:推到高塔
 * Description:
 * Version: V1.0
 */
@WebServlet(name="CostFangShiServlet",value="/costManage/zhifu")
public class CostFangShiServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String chargeRecordId = request.getParameter("chargeRecordId");
        String paymentMethod = request.getParameter("paymentMethod");
        String costTime = request.getParameter("costTime");
        //把String类型的2024-12-19 14:47:34转成Date类型的
        Date costTime2= MyFormatUtils.toDate(costTime);
        System.out.println("paymentMethod:"+paymentMethod);
        System.out.println("costTime:"+costTime);
        //创建支付方式
        PeopleCostVo peopleCostVo= new PeopleCostVo();
        peopleCostVo.setCostTime(costTime2);
        peopleCostVo.setPaymentMethod(paymentMethod);
        peopleCostVo.setChargeRecordId(chargeRecordId);

        CostManagementService service=new CostManagementServiceImpl();
        boolean update=false;
        if(paymentMethod.equals("线下支付")){
           update = service.updateCostById(peopleCostVo);
        }else if(paymentMethod.equals("催缴")){
           update = service.Cuijiao(peopleCostVo);
        }
        R r=!update? R.error("更新成功"):R.ok();
        PrintWriter writer = response.getWriter();
        String result = JSON.toJSONString(r);
        System.out.println("chazhao"+result);
        writer.write(result);
        writer.flush();
        writer.close();
    }
}


